#include<bits/stdc++.h>
#define ll __int128
#define int long long
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(!x)
        putchar('0');
    char F[200];
    int tmp=x>0?x:-x;
    if(x<0)
        putchar('-');
    int cnt=0;
    while(tmp>0)
        F[cnt++]=tmp%10+'0',tmp/=10;
    while(cnt>0)
        putchar(F[--cnt]);
}
const int maxn=5e5+10;
vector<pair<int,int>> alls[maxn];
int a[maxn],s[maxn];
int n,m;
struct node
{
	int x,y;
	inline friend bool operator > (node x,node y)
	{
		return (ll)x.x*y.y>(ll)y.x*x.y;
	}
}ans[maxn],t[maxn];
inline int lowbit(int x)
{
	return x&(-x);
}
inline void add(int x,node v)
{
	for(;x;x-=lowbit(x))
		if(v>t[x]||t[x].x==-1) t[x]=v;
}
inline node query(int x)
{
	node res=t[x];
	for(;x<=n;x+=lowbit(x))
		if(t[x].x!=-1&&(res.x==-1||t[x]>res)) res=t[x];
	return res;
}
signed main()
{
	freopen("value.in","r",stdin);
	freopen("value.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		s[i]=s[i-1]+a[i];
		t[i].x=-1;
	}
	cin>>m;
	int lim=sqrt(2e8/m);
	for(int p=1;p<=m;p++)
	{
		int l,r,mx1=-1,mx2,ansl,ansr;
		cin>>l>>r;
		ans[p].x=-1;
		for(int i=l;i<=min(l+lim,r);i++)
		{
			for(int j=max(i,r-lim);j<=r;j++)
			{
				int sum=s[j]-s[i-1];
				node tmp=(node){sum*sum,j-i+1};
				if(ans[p].x==-1||tmp>ans[p]) 
					ans[p]=tmp;
			}			
		}
		alls[r].push_back({l,p});
	}
	lim=4e8/n;
	for(int i=1;i<=n;i++)
	{
		node nw=(node){-1,0};
		for(int j=i;j>max(0ll,i-lim);j--)
		{
			int sum=s[i]-s[j-1];
			node tmp=(node){sum*sum,i-j+1};
			if(nw.x==-1||tmp>nw)
			{
				nw=tmp;
				add(j,nw);
			}
		}
		for(auto p:alls[i])
		{
			int l=p.first,id=p.second;
			node res=query(p.first);
			if(res>ans[id]) 
				ans[id]=res;
		}
	}
	for(int i=1;i<=m;i++)
	{
		int x=ans[i].x,y=ans[i].y,g=__gcd(x,y);
		cout<<x/g<<' '<<y/g<<'\n'; 
	}
	return 0;
}

